package com.deyuanyun.pic.settings.controller.org;

import com.deyuanyun.pic.common.util.RequestUtil;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.settings.controller.dto.org.DeptVO;
import com.deyuanyun.pic.settings.service.org.DeptService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 部门信息管理
 * 
 * 
 *
 * @author    王敏
 * @version   2015年12月15日下午2:47:45
 * Method List:                       
 *				toPage 进入部门管理 列表界面
 *				search 查询数据
 *				save   添加数据
 *				update 修改数据
 *				del    删除数据
 */
@Controller
@RequestMapping("/settings/org/dept")
public class DeptController {

	@Resource
	DeptService deptService;
	
	
	@RequestMapping(value="/page.html",method=RequestMethod.GET)
	public ModelAndView toPage( ModelAndView mav)
	{
		mav.setViewName("/settings/org/dept");
		return mav;
	}
	
	@RequestMapping("/searchInfo.json")
	@ResponseBody
	public void searchInfo(DeptVO deptVO) {
		AjaxSupport.sendSuccessText("ok", deptService.queryAll(deptVO));
	}

	@RequestMapping(value="/add.json", method=RequestMethod.POST)
	@ResponseBody
	public void save(DeptVO deptVO) {
	    deptService.saveInfo(deptVO);
        AjaxSupport.sendSuccessText("success", "保存成功!");
	}

	@RequestMapping(value="/updateState", method=RequestMethod.POST)
	@ResponseBody
	public void updateState( HttpServletRequest request) {
		HashMap param= RequestUtil.parseRequestParamToHashMap(request);
        deptService.updateState(param);
		AjaxSupport.sendSuccessText("success", "");
	}
	
	@RequestMapping(value="/update", method=RequestMethod.POST)
	@ResponseBody
	public void update(DeptVO deptVO) {
		deptService.updateInfo(deptVO);
        AjaxSupport.sendSuccessText("success", "更新成功!");
	}
	
	@RequestMapping(value="/del", method=RequestMethod.POST)
	@ResponseBody
	public void del(@RequestParam("idList") List<String> idList) {
		int n = deptService.deleteInfo(idList);
        AjaxSupport.sendSuccessText(Integer.toString(n), "删除成功！");
	}
}
